﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Media;
using Safe_Driving.TokenUser;
using DbLinq.Data.Linq;

namespace Safe_Driving
{
    public partial class MainWindow
    {
        

        public void RemplirZonesVehicules()
        {
            SingletonTokenUser token = SingletonTokenUser.GetInstance();
            AppSafeDriving app = (AppSafeDriving)token.DbApp;

            IEnumerable<string> lesZones = (from z in app.SFZone
                                join a in app.SFAgeNcE on z.IdaGenCe equals a.IdaGenCe
                                where a.IdaGenCe == token.Agence.IdaGenCe
                                select z.TypeZone);
            
            foreach(string sfz in lesZones)
                cbxZones.Items.Add(sfz.ToString());

            if (cbxZones.Items.Count > 0)
                cbxZones.SelectedIndex = 0;
        }


        public void ChargerImage()
        {
            string zoneChoisie = /*SupprimerAccents(*/cbxZones.SelectedItem.ToString().ToLower();
            string pathImage = @"../../Images/Circuits/" + zoneChoisie + ".png";
            try
            {
                imgZone.Source = new ImageSourceConverter().ConvertFromString(pathImage) as ImageSource;
            }
            catch (Exception)
            {
            }
        }

        /*
        //Retourne une chaîne sans accents. Utilisé pour obtenir le path des images
        public String SupprimerAccents(String s)
        {
            String aNormaliser = s.Normalize(NormalizationForm.FormD);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < aNormaliser.Length; i++)
            {
                Char c = aNormaliser[i];
                if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                    sb.Append(c);
            }
            return sb.ToString();
        } */
    }
}
